import React, { useState, useEffect } from 'react';

function Reminder(props) {
  const [timerID, setTimerID] = useState(null);

  const [counter, setCounter] = useState(5);

  useEffect(() => {
    if (counter > 0) {
      let timer = setTimeout(() => {
        setCounter(counter - 1);
      }, 1000);
      setTimerID(timer);
    } else {
      props.history.push('/order');
    }

    return () => {
      setTimerID(null);
    };
  }, [counter]);

  return (
    <div>
      <p>{counter}秒后将自动跳转至订单页面...</p>
    </div>
  );
}

export default Reminder;
